import fs from 'fs'
import gp from 'get-pixels'
import { encryptImg, decryptImg } from './core.js'
import jpg from 'jpeg-js'

gp('./1.jpg', (e, px) => {

  if (e) {
    console.log(e);
    return
  }

  // 获取图片数据
  const { data, shape: [width, height] } = px
  console.log('encrypto begin', Date.now());

  const encryptData = encryptImg({
    width,
    height,
    data: data.toJSON().data
  })

  fs.writeFileSync('enc.jpg', jpg.encode(encryptData).data)

  console.log('encrypto end', Date.now());

  const decryptData = decryptImg(encryptData)

  console.log('decrypto begin', Date.now());

  fs.writeFileSync('dec.jpg', jpg.encode(decryptData).data)

  console.log('decrypto end', Date.now());
})

